#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

using namespace std;

class Solution {
public:
    bool isPowerOfFour(int num) {
        while (num > 3) {
            if (num % 4 != 0)
                return false;
            num /= 4;
        }
        if (num == 1)
            return true;
        else
            return false;
    }
}


int countBinarySubstrings(char* s) {
    int n = strlen(s);
    int counts[n], counts_len = 0;
    memset(counts, 0, sizeof(counts));
    int ptr = 0;
    while (ptr < n) {
        char c = s[ptr];
        int count = 0;
        while (ptr < n && s[ptr] == c) {
            ++ptr;
            ++count;
        }
        counts[counts_len++] = count;
    }
    int ans = 0;
    for (int i = 1; i < counts_len; ++i) {
        ans += fmin(counts[i], counts[i - 1]);
    }
    return ans;
}

